package com.epalmpay.controller.agent.datareport;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.annotation.Resource;

import com.epalmpay.entity.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.datareport.TransDataReportInDTO;
import com.epalmpay.dto.datareport.TransDataReportListOutDTO;
import com.epalmpay.service.datareport.ITransDataReportService;

/** 
 * 说明：数据报表 :营销数据列表
 * 创建人：gwn
 * 创建时间：2017-06-27
 */

@Controller
@RequestMapping(value="/agent/transDataReport")
public class AgentTransDataReportController extends BaseController{
	
	@Resource
	private ITransDataReportService transDataReportService;

	
	@RequestMapping(value="/list")
	@ResponseBody
	public TransDataReportListOutDTO list(TransDataReportInDTO transDataReportInDTO){
		TransDataReportListOutDTO transDataReportListOutDTO = new TransDataReportListOutDTO();
		try {
			//查询日的
			if (transDataReportInDTO.getQueryDayOrMonth()==1) {
				if (transDataReportInDTO.getJoinStart()==null) {
//					transDataReportInDTO.setJoinStart(new Date());
					Date date=new Date();//取时间
					Calendar calendar = new GregorianCalendar();
					calendar.setTime(date);
					calendar.add(calendar.DATE,-1);//把日期往前减少一天，若想把日期向后推一天则将负数改为正数
					date=calendar.getTime();
					transDataReportInDTO.setJoinStart(date);
				}
				//刷卡交易金额 扫码付交易金额  台卡收银金额
				StatisShopDay statisShopDay= transDataReportService.queryAgentStatisShopDayData(transDataReportInDTO);
				transDataReportListOutDTO.setStatisShopDay(statisShopDay);

				//现金
				TradeOffline tradeOffline2=transDataReportService.queryAgentCash(transDataReportInDTO);
				transDataReportListOutDTO.setTradeOffline2(tradeOffline2);

			}
			
			//查询月的
			if (transDataReportInDTO.getQueryDayOrMonth()!=1) {
				StatisShopMonth statisShopMonth= transDataReportService.queryAgentStatisShopMonthData(transDataReportInDTO);
				transDataReportListOutDTO.setStatisShopMonth(statisShopMonth);

				TradeOffline tradeOffline2=transDataReportService.queryAgentCash(transDataReportInDTO);
				transDataReportListOutDTO.setTradeOffline2(tradeOffline2);

			}
			
			transDataReportListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return transDataReportListOutDTO;
		} catch (ApplicationException ae) { 
			transDataReportListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}catch (Exception e) {
			transDataReportListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
				e.printStackTrace();
		}
		return transDataReportListOutDTO;
		
	}
	
	

}

